package com.wpx.Controller;

import com.wpx.Pojo.Paragraph;
import com.wpx.Pojo.Word;
import com.wpx.Service.WordService;
import com.wpx.Util.PinYinUtil;
import com.wpx.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/word")
public class WordController {

@Autowired
 public   WordService wordService;



    @GetMapping("/getwordlist")
    public Result getwordlist(@RequestParam String content){
          List< List<Word>> llw= wordService.getwordlist(content);
          return  Result.ok(llw);
    }
    @GetMapping("/getwordlistById")
    public Result getwordlistById(@RequestParam Integer articleId){
        List< List<Word>> llw= wordService.getwordlistById(articleId);
        return  Result.ok(llw);
    }
    @GetMapping("/getPinyins")
    public Result getPinyins(@RequestParam String word){
        if(word==null||word.length()!=1){
            return Result.fail("传参异常");
        }
        String[]fullPinyin = PinYinUtil.getFullPinyin(word.charAt(0));
        return  Result.ok(fullPinyin);
    }
    @PostMapping("/updatePinyin")
    public Result updatePinyin(@RequestBody Word word){
        wordService.updatePinyin(word);
        return  Result.ok();
    }
    @PostMapping("/updateBold")
    public Result updateBold(@RequestBody Word word){
        wordService.updateBold(word);
        return  Result.ok();
    }
}


